package com.teamwork.module01.controller;

import com.teamwork.common.entity.module01.Class;
import com.teamwork.common.entity.module01.Paike;
import com.teamwork.common.result.Result;
import com.teamwork.module01.service.PaikeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/mod01/paike")
@Slf4j
public class PaikeController {

    @Resource
    private PaikeService paikeService;
    private Map<String, Integer> ids;

    //根据学生id查询排课信息
    @GetMapping
    public Result getByStuId(Long id){
        return paikeService.getByStuId(id);
    }

    @GetMapping("/getbyname")
    public Result getByname(String name){
        return paikeService.getByName(name);
    }
    @GetMapping("/page")
    public Result page(Integer page,Integer size){
        //log.info("{}",page+","+size);
        return paikeService.getPage(page,size);
    }
    @PostMapping
    public Result InsertOrUpdate(@RequestBody Paike paike){
       // log.info("添加的排课信息为：{}",paike);

        return paikeService.InsertOrUpdate(paike);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        return paikeService.deleteById(id);
    }
    @DeleteMapping
    public Result batchDelete(@RequestBody Map<String,Integer[]> map){

       // log.info("{}",ids);

        Integer[] ids1 = map.get("ids");

        List<Integer> idlist = Arrays.asList(ids1);

        return paikeService.batchDelete(idlist);
    }
}
